package be.kuleuven.thesis.pages;

import java.util.ArrayList;

import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

public class CurrentPlaylistGroup extends ActivityGroup{
	public static CurrentPlaylistGroup group;
	private ArrayList<View> history;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.history = new ArrayList<View>();
		group = this;
		
		// Start the root activity withing the group and get its view
				View view = getLocalActivityManager().startActivity("CurrentPlaylistActivity",
						new Intent(this,CurrentPlaylist.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
				
				history.clear();

				// Replace the view of this ActivityGroup
				replaceView(view);
	}
	
//	@Override
//	public void onResume() {
//		super.onResume();
//		
//	}

	public void replaceView(View view) {
		history.add(view);
		// Changes this Groups View to the new View.
		setContentView(view);
	}

	public void back() {
		if(history.size() > 1) {
			history.remove(history.size()-1);
			setContentView(history.get(history.size()-1));
		}else {
			GenerecsTabActivity.tabActivity.back();
		}
	}

	@Override
	public void onBackPressed() {
		back();
		return;
	}

}
